using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;

namespace Janus.NorthwindDemo2007
{
	public class frmShippers : System.Windows.Forms.Form
	{

	#region  Windows Form Designer generated code 

		public frmShippers() : base()
		{

			//This call is required by the Windows Form Designer.
			InitializeComponent();

			//Add any initialization after the InitializeComponent() call

		}

		//Form overrides dispose to clean up the component list.
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		//Required by the Windows Form Designer
		private System.ComponentModel.IContainer components;

		//NOTE: The following procedure is required by the Windows Form Designer
		//It can be modified using the Windows Form Designer.  
		//Do not modify it using the code editor.
		internal System.Windows.Forms.ImageList imlIcons;
		internal Janus.Windows.GridEX.GridEX GridEX1;
		internal System.Windows.Forms.OpenFileDialog OpenFileDialog1;
		internal Janus.Windows.EditControls.UIButton btnOk;
		internal Janus.Windows.EditControls.UIButton btnCancel;
		internal Janus.Windows.EditControls.UIButton UiButton1;
		internal Janus.Windows.EditControls.UIButton btnAdd;
		internal Janus.Windows.EditControls.UIButton btnDelete;
		internal Janus.NorthwindDemo2007.NorthwindData dsNorthwind;
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmShippers));
            Janus.Windows.GridEX.GridEXLayout gridEXLayout1 = new Janus.Windows.GridEX.GridEXLayout();
            this.imlIcons = new System.Windows.Forms.ImageList(this.components);
            this.GridEX1 = new Janus.Windows.GridEX.GridEX();
            this.dsNorthwind = new Janus.NorthwindDemo2007.NorthwindData();
            this.OpenFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.btnOk = new Janus.Windows.EditControls.UIButton();
            this.btnCancel = new Janus.Windows.EditControls.UIButton();
            this.UiButton1 = new Janus.Windows.EditControls.UIButton();
            this.btnAdd = new Janus.Windows.EditControls.UIButton();
            this.btnDelete = new Janus.Windows.EditControls.UIButton();
            ((System.ComponentModel.ISupportInitialize)(this.GridEX1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dsNorthwind)).BeginInit();
            this.SuspendLayout();
            // 
            // imlIcons
            // 
            this.imlIcons.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imlIcons.ImageStream")));
            this.imlIcons.TransparentColor = System.Drawing.Color.Magenta;
            this.imlIcons.Images.SetKeyName(0, "");
            // 
            // GridEX1
            // 
            this.GridEX1.AllowAddNew = Janus.Windows.GridEX.InheritableBoolean.True;
            this.GridEX1.AllowDelete = Janus.Windows.GridEX.InheritableBoolean.True;
            this.GridEX1.CardBorders = false;
            this.GridEX1.CardHeaders = false;
            this.GridEX1.CardSpacing = 4;
            this.GridEX1.CardWidth = 268;
            this.GridEX1.CenterSingleCard = false;
            this.GridEX1.Cursor = System.Windows.Forms.Cursors.Default;
            this.GridEX1.DataMember = "Shippers";
            this.GridEX1.DataSource = this.dsNorthwind;
            gridEXLayout1.LayoutString = resources.GetString("gridEXLayout1.LayoutString");
            this.GridEX1.DesignTimeLayout = gridEXLayout1;
            this.GridEX1.ExpandableCards = false;
            this.GridEX1.Location = new System.Drawing.Point(4, 7);
            this.GridEX1.Name = "GridEX1";
            this.GridEX1.NewRowPosition = Janus.Windows.GridEX.NewRowPosition.BottomRow;
            this.GridEX1.RecordNavigator = true;
            this.GridEX1.SaveSettings = false;
            this.GridEX1.ScrollBarWidth = 17;
            this.GridEX1.Size = new System.Drawing.Size(280, 147);
            this.GridEX1.TabIndex = 0;
            this.GridEX1.View = Janus.Windows.GridEX.View.SingleCard;
            // 
            // dsNorthwind
            // 
            this.dsNorthwind.DataSetName = "NorthwindData";
            this.dsNorthwind.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
            // 
            // OpenFileDialog1
            // 
            this.OpenFileDialog1.Filter = "Image Files|*.bmp;*.jpg;*.gif|All Files|*.*";
            this.OpenFileDialog1.Title = "Select a Picture";
            // 
            // btnOk
            // 
            this.btnOk.Location = new System.Drawing.Point(290, 8);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new System.Drawing.Size(93, 26);
            this.btnOk.TabIndex = 6;
            this.btnOk.Text = "OK";
            this.btnOk.Click += new System.EventHandler(this.btnOK_Click);
            // 
            // btnCancel
            // 
            this.btnCancel.Location = new System.Drawing.Point(290, 38);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(93, 26);
            this.btnCancel.TabIndex = 7;
            this.btnCancel.Text = "Cancel";
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // UiButton1
            // 
            this.UiButton1.Location = new System.Drawing.Point(290, 68);
            this.UiButton1.Name = "UiButton1";
            this.UiButton1.Size = new System.Drawing.Size(93, 26);
            this.UiButton1.TabIndex = 8;
            this.UiButton1.Text = "Select Picture...";
            this.UiButton1.Click += new System.EventHandler(this.Button1_Click);
            // 
            // btnAdd
            // 
            this.btnAdd.Location = new System.Drawing.Point(290, 98);
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(93, 26);
            this.btnAdd.TabIndex = 9;
            this.btnAdd.Text = "Add";
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnDelete
            // 
            this.btnDelete.Location = new System.Drawing.Point(290, 128);
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new System.Drawing.Size(93, 26);
            this.btnDelete.TabIndex = 10;
            this.btnDelete.Text = "Delete";
            this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
            // 
            // frmShippers
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(386, 159);
            this.Controls.Add(this.btnDelete);
            this.Controls.Add(this.btnAdd);
            this.Controls.Add(this.UiButton1);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOk);
            this.Controls.Add(this.GridEX1);
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Name = "frmShippers";
            this.Text = "Shippers";
            this.Load += new System.EventHandler(this.frmShippers_Load);
            ((System.ComponentModel.ISupportInitialize)(this.GridEX1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dsNorthwind)).EndInit();
            this.ResumeLayout(false);

		}

	#endregion

		private DataView mData;
		public DataView Data
		{
			get
			{
				return mData;
			}
			set
			{
				if (mData != value)
				{
					mData = value;
					this.GridEX1.SetDataBinding(mData, "");
				}
			}
		}



		private void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{

				this.DialogResult = System.Windows.Forms.DialogResult.OK;
				Close();
			}
			catch (Exception exc)
			{
				MessageBox.Show(exc.Message, NorthwindApp.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			if (mData != null)
			{
				mData.Table.DataSet.Tables["Shippers"].RejectChanges();
			}
			this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			Close();
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			if (this.OpenFileDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
			{
				try
				{
					Bitmap img = null;
					img = (Bitmap)Image.FromFile(this.OpenFileDialog1.FileName);
					this.GridEX1.SetValue("SmallIcon", img);
					this.GridEX1.UpdateData();
				}
				catch
				{
					MessageBox.Show("Invalid Picture.", NorthwindApp.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
			}
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			this.GridEX1.Delete();
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			GridEX1.MoveToNewRecord();
		}

		private void frmShippers_Load(object sender, System.EventArgs e)
		{
			NorthwindApp.MainForm.VisualStyleManager1.AddControl(this, true);

		}
	}

} //end of root namespace